package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.tree.AbstractLayoutCache;
	
	public class FrameBattleAuto extends JFrame
	{
		//members define
		private var panelImage:JPanel;
		private var btn_battle_auto_switch:JButton;
		private var btn_battle_auto_setting:JButton;
		public function FrameBattleAuto()
		{
			setClosable(false);
			setResizable(false);  
			setTitleBar(null);
			setBorder(new EmptyBorder());
			this.setBackgroundDecorator(new SolidBackground(new ASColor(0,0)));
			this.setClipMasked(false);
			this.getContentPane().setClipMasked(false);
			
			//component creation
			setSize(new IntDimension(250, 57));
			setPreferredSize(new IntDimension(250, 57));
			var layout0:EmptyLayout = new EmptyLayout();
			getContentPane().setLayout(layout0);
			
			panelImage = new JPanel();
			panelImage.setLocation(new IntPoint(0, 0));
			panelImage.setSize(new IntDimension(250, 29));
			panelImage.setPreferredSize(new IntDimension(250, 29));
			
			btn_battle_auto_switch = new JButton();
			btn_battle_auto_switch.setLocation(new IntPoint(44, 29));
			btn_battle_auto_switch.setSize(new IntDimension(115, 28));
			btn_battle_auto_switch.setPreferredSize(new IntDimension(115, 28));
			btn_battle_auto_switch.setText("label");
			
			btn_battle_auto_setting = new JButton();
			btn_battle_auto_setting.setLocation(new IntPoint(159, 30));
			btn_battle_auto_setting.setSize(new IntDimension(47, 26));
			btn_battle_auto_setting.setPreferredSize(new IntDimension(47, 26));
			btn_battle_auto_setting.setText("label");
			
			//component layoution
			getContentPane().append(panelImage);
			getContentPane().append(btn_battle_auto_switch);
			getContentPane().append(btn_battle_auto_setting);
			//------------------------------------------
			setImages();
		}
		public function setImages():void
		{
			setBackgroundDecorator(null);
			btn_battle_auto_switch.wrapSimpleButton(Client.getUIElement("btn_battle_auto_switch") as SimpleButton);
			btn_battle_auto_switch.setText("");
			btn_battle_auto_setting.wrapSimpleButton(Client.getUIElement("btn_battle_auto_setting") as SimpleButton);
			btn_battle_auto_setting.setText("");
			setLocationXY((Engine.W - width) / 2,465);
			btn_battle_auto_setting.addActionListener(function ():void
			{
				FrameBattleSetting.show();
			});
			
			btn_battle_auto_switch.addActionListener(function ():void
			{
				FrameBattleAuto.updateBattleAuto();
			});

			
			img_battle_system_bg = new AssetBackground(Client.getUIElement("img_battle_system_bg") as DisplayObject);
			img_battle_auto_bg = new AssetBackground(Client.getUIElement("img_battle_auto_bg") as DisplayObject);
			
			panelImage.setBackgroundDecorator(SceneBattle.nLearning == 1 ? img_battle_system_bg : img_battle_auto_bg);
		}
		private var img_battle_system_bg:AssetBackground = null;
		private var img_battle_auto_bg:AssetBackground = null;
		
		public static function updateBattleAuto(mode:int = -1):void
		{
			if(mode == -1)
			{
				if(CharInfo.m_nBattleMode == 0)
					CharInfo.m_nBattleMode = 1;
				else
					CharInfo.m_nBattleMode = 0;
			}
			else
			{
				CharInfo.m_nBattleMode = mode;
			}
			FrameBattleAuto.update();
			
			var array:Array = new Array();
			array.push(FrameBattleSetting.BATTLE_SETTING_TYPE_CHAR);
			array.push(0);
			array.push(0);
			array.push(CharInfo.m_nBattleMode);
			var item:uint = 0;
			for each(item in CharInfo.m_arAutoBattleSkills)
			{
				array.push(item);
			}
			//for each(item in CharInfo.m_arAutoBattleSkillsPet)
			//{
			//	array.push(item);
			//}
			Client.getInstance().sendPacketLogic(320,array);
			
			if(CharInfo.m_nBattleMode == 1 && SceneBattle.isWaitUseSkill)
			{
				FrameBattle.show();
			}
			if(CharInfo.m_nBattleMode == 0)
			{
				FrameBattle.hide();
				FrameBattle.hidePartner();
			}
		}
		
		public static var _frame:FrameBattleAuto = null;
		public static function show():void
		{
			if(SceneBattle.bWatchingBattle)
			{
				FrameBattleWatch.show();
				FrameBattle.hide();
				FrameBattleAuto.hide();
				return;
			}
			FrameBattleWatch.hide();
			if(_frame == null)
			{
				_frame = new FrameBattleAuto();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			_frame.show();
			_frame.panelImage.setBackgroundDecorator(SceneBattle.nLearning == 1 ? _frame.img_battle_system_bg : _frame.img_battle_auto_bg);

			_frame.btn_battle_auto_switch.setVisible(SceneBattle.nLearning == 0);
			_frame.btn_battle_auto_setting.setVisible(SceneBattle.nLearning == 0);
			
			PanelMainHelp.getInstance().bringToTop(_frame);
			
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
		
		public static function update():void
		{
			if((CharInfo.m_nBattleMode == 0 || SceneBattle.nLearning == 1)&& PanelMain.getInstance().isInBattle)
				show();
			else
				hide();
		}
	}
}